<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('合同财务列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse hidden">
                <form id="formId">
                    <div class="select-list">
                        <ul>
<!--                            <input name="accountId" th:value="${accountId}"  id="accountId" type="hidden">-->
                            <li>
                                <label>订单号：</label>
                                <input type="text" name="orderId"/>
                            </li>
                            <li>
                                <label>金额：</label>
                                <input type="text" name="totalMoney"/>
                            </li>
                            <li>
                                <label>付款时间：</label>
                                <input type="text" class="time-input" placeholder="请选择付款时间" name="payTime"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="contractFinance:contractFinance:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled hidden" onclick="$.operate.edit2()" shiro:hasPermission="contractFinance:contractFinance:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled hidden" onclick="$.operate.removeAll()" shiro:hasPermission="contractFinance:contractFinance:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning hidden" onclick="$.table.exportExcel()" shiro:hasPermission="contractFinance:contractFinance:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table-finance"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('contractFinance:contractFinance:edit')}]];
        var removeFlag = [[${@permission.hasPermi('contractFinance:contractFinance:remove')}]];
        var accountId = [[${accountId}]];
        let type = [[${type}]];
        let contractId=[[${contractId}]];
        var prefix = ctx + "contractFinance/contractFinance";
        let url= prefix + "/list?";
        let createUrl= prefix + "/add?";
        if(!isEmptyString(accountId)){
            url = url+"accountId="+accountId+"&type="+type;
            createUrl=createUrl+"accountId="+accountId+"&type="+type+"&contractId="+contractId;
        }

        var options = {
            id:"bootstrap-table-finance",
            showFooter: true,
            url: url,
            createUrl: createUrl,
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "financeId",
            sortOrder:"desc",
            footerStyle: footerStyle,
            modalName: "财务",
            columns: [{
                checkbox: true
            },
                {
                    field: 'financeId',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'financeNo',
                    title: '付款编号'
                },
                {
                    field: 'accountNo',
                    title: '账单号',
                },
                {
                    field: 'files',
                    title: '附件',
                    formatter: function(value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'totalMoney',
                    title: '金额',
                    footerFormatter:function (value) {
                        var totalMoney = 0;
                        for (var i in value) {
                            totalMoney += parseFloat(value[i].totalMoney);
                        }
                        return "总金额：" + totalMoney;
                    }
                },
                {
                    field: 'createBy',
                    title: '创建者'
                },
                {
                    field: 'payTime',
                    title: '付款时间'
                },

                {
                    field: 'createTime',
                    title: '创建时间'
                },

                {
                    field: 'remark',
                    title: '备注'
                }]
        };
        $(function() {
            $.table.init(options);
        });
        function footerStyle(column) {
            return {
                totalMoney: {
                    css: { color: 'red', 'font-weight': 'normal' }
                }
            }[column.field]
        }

        function add() {
            let title=type==financeType.shoukuang?"财务收款记录":"财务付款记录";
            openWinRefresh(title,prefix + "/add?accountId="+accountId+"&type="+type+"&contractId="+contractId);
        }
    </script>
</body>
</html>
